package com.hrcx.mystery.controller;

import com.alibaba.fastjson.JSONObject;
import com.hrcx.mystery.common.CommonPage;
import com.hrcx.mystery.common.CommonResult;
import com.hrcx.mystery.common.PageParamRequest;
import com.hrcx.mystery.dto.MysteryConsignmentDto;
import com.hrcx.mystery.service.EbMysteryUserConsignmentService;
import com.hrcx.mystery.vo.EbMysteryUserConsignmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <h1>盲盒寄售请求控制器</h1>
 *
 * @author LinXiPeng
 * @className MysteryCompoundController
 * @date 2021/12/20 17:20
 * Version 1.0
 */
@RestController
@Api(tags = "盲盒寄售")
@RequestMapping("/api/mystery/compound")
public class MysteryCompoundController {
    @Resource
    private EbMysteryUserConsignmentService consignmentService;

    @ApiOperation("寄售奖品(从记录编号生成)")
    @RequestMapping(value = "/compoundPrize", method = RequestMethod.POST)
    public CommonResult<JSONObject> compoundPrize(@RequestParam Integer rid, @RequestParam BigDecimal price) {
        return consignmentService.compoundPrize(rid, price) ? CommonResult.success("寄售请求成功") : CommonResult.failed("寄售请求失败");
    }

    @ApiOperation("取消寄售奖品")
    @RequestMapping(value = "/cancelCompoundPrize", method = RequestMethod.DELETE)
    public CommonResult<JSONObject> cancelCompoundPrize(@RequestParam Integer cid) {
        return consignmentService.cancelCompoundPrize(cid) ? CommonResult.success("寄售取消成功") : CommonResult.failed("寄售取消失败");
    }

    @ApiOperation("查询寄售的奖品")
    @RequestMapping(value = "/getCompoundPrize", method = RequestMethod.GET)
    public CommonResult<CommonPage<EbMysteryUserConsignmentVo>> getCompoundPrize(@Validated MysteryConsignmentDto consignmentDto,
                                                                                 @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(consignmentService.getCompoundPrize(consignmentDto, pageParamRequest)));
    }
}